local key = KEYS[1]
local maxValue = tonumber(ARGV[1])

local value = redis.call("incrby", key, 1)
if value > maxValue then
    redis.call("set", key, 1)
    return 1
end
return value
